package com.cy;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@SpringBootApplication
public class ProviderAppRun {
    public static void main(String[] args) {
        SpringApplication.run(ProviderAppRun.class, args);
    }

//    @RefreshScope
    @RestController
    @RequestMapping("/provider")
    public class ProviderController{
        public ProviderController(){
            System.out.println("==构造方法==");
        }
        //给定默认值，如果没有默认值，启动时读取不到会报错
        @Value("${logging.level.com.cy:debug}")
        private String loglevel;
        @Value("${server.port:8080}")
        private String servser;

        @GetMapping("/echo/{msg}")
        public String doRestEcho(@PathVariable String msg) throws InterruptedException {
//            Thread.sleep(5000);
            log.info("当前程序的启动时间为：{}", (new Date()));
            return servser+"你好"+msg;
        }
        @GetMapping("/getLoglevel")
        public String getLoglevel(){
            log.trace("==trace跟踪日志，级别最低==");
            log.debug("==debug调试日志，二级日志==");
            log.info("==info常规日志，三级日志==");
            log.warn("==warn警告日志，四级日志==");
            log.error("==错误信息，最高级日志==");
            return "当前的日志级别为："+loglevel;
        }
    }
}
